package com.ss.android.article.base.feature.e;

import android.app.Activity;
import android.content.DialogInterface;

import com.bytedance.article.common.c.JSONObjectWrapper;
import com.bytedance.common.utility.Logger;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.c.ImageManager;
import com.ss.android.article.base.feature.detail.model.ArticleDetail;
import com.ss.android.article.base.feature.detail.model.ArticleInfo;
import com.ss.android.article.base.feature.detail.presenter.DetailHelper;
import com.ss.android.article.base.feature.detail.view.DetailActionDialog;
import com.ss.android.article.base.feature.detail2.c.NewArticleDetailTTAndroidObject;
import com.ss.android.article.base.feature.feed.m;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.MediaInfo;
import com.ss.android.article.base.ui.BaseActionDialog;
import com.ss.android.article.base.ui.BaseActionDialog.CtrlFlag;
import com.ss.android.article.base.ui.BaseActionDialog.DisplayMode;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.model.e;
import com.ss.android.article.common.share.abs.AbsShareHelper;
import com.ss.android.article.common.share.helper.CommonQQShareHelper;
import com.ss.android.article.common.share.helper.CommonQZoneShareHelper;
import com.ss.android.article.common.share.helper.CommonWXShareHelper;
import com.ss.android.article.share.e.b;
import com.ss.android.common.callback.CallbackCenter;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.newmedia.BaseAppData;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.EnumSet;

public final class ArticleShareHelper {
    public interface a$a {
        void shareContent(long arg1);
    }

    private AppData mAppData;
    private String B;
    private boolean C;
    private b D;
    Activity mActivity;
    Article mArticle;
    long c;
    ArticleActionHelper mActionHelper;
    public NewArticleDetailTTAndroidObject mNewArticleDetailTTAndroidObject;
    public DetailHelper mDetailHelper;
    public b g;
    public a$a h;
    public int mShareSource;
    public String mCategoryName;
    public JSONObject mExtJsonObj;
    public ArticleInfo l;
    public String detailSource;
    DisplayMode mDisplayMode;
    EnumSet o;
    public String p;
    public boolean q;
    public ArticleDetail mArticleDetail;
    public String s;
    public String position;
    public static final e u = new e("video_list_share_button");
    public boolean v;
    public int w;
    public m x;
    public boolean y;
    DialogInterface.OnClickListener mDeleteAnswerConfirmListener;

    public ArticleShareHelper(Activity arg7, ArticleActionHelper arg8, DetailHelper arg9, int arg10) {
        this(arg7, arg8, arg9, arg10, false);
    }

    public ArticleShareHelper(Activity arg3, ArticleActionHelper arg4, DetailHelper arg5, int arg6, boolean arg7) {

        this.position = "";
        this.C = false;
        this.y = false;
        this.D = new c(this);
        this.mDeleteAnswerConfirmListener = new com.ss.android.article.base.feature.e.e(this);
        this.C = arg7;
        this.mActivity = arg3;
        this.mActionHelper = arg4;
        this.mDetailHelper = arg5;
        this.mShareSource = arg6;
        this.mAppData = AppData.getInstance();
        new ImageManager(this.mActivity);
        String v0 = this.mShareSource == 200 ? "detail_share" : "list_share";
        this.B = v0;
    }

    public final void share(int platform, Article article) {
        if (platform >= 0 && article != null) {
            this.mArticle = article;
            switch (platform) {
                case 1:
                    this.shareToWechat(1);
                    return;
                case 2:
                    this.shareToWechat(0);
                    return;
                case 3:
                    this.shareToQQ();
                    return;
                case 4:
                    this.shareToQZone();
                    return;
            }

            return;
        }
    }

    public final void fillShareParams(JSONObject params) {
        if (params != null) {
            JSONObject extJsonObj = this.createExtJsonObj();
            JSONObjectWrapper jsonObjectWrapper = new JSONObjectWrapper();
            jsonObjectWrapper.put(extJsonObj);
            jsonObjectWrapper.put(params);
            this.mExtJsonObj = jsonObjectWrapper.jo;
        }
    }

    public final void a(Article arg8, ArticleInfo arg9, long arg10) {
        this.l = arg9;
        this.a(arg8, arg10, DisplayMode.DETAIL_MENU, false);
    }

    public final void a(Article arg9, long arg10, boolean arg12) {
        e v7 = null;
        if (arg9 != null) {
            if (arg9.hasVideo()) {
                this.a(arg9, arg10, arg12, DisplayMode.SHARE_VIDEO_DETAIL, true, v7);
            } else {
                this.a(arg9, arg10, arg12, DisplayMode.SHARE, true, v7);
            }
        }
    }

    static void a(ArticleShareHelper arg0) {
        arg0.shareToQZone();
    }

    static void a(ArticleShareHelper arg0, String arg1, String arg2, String arg3) {
        arg0.a(arg1, arg2, arg3);
    }

    final void a(String arg7, String arg8, String arg9) {
        if (!android.support.design.a.isTextEmpty(this.B) && this.mActivity != null) {
            long v0 = 0;
            if (this.mArticle != null) {
                v0 = this.mArticle.groupId;
            }

            JSONObject v3 = this.createExtJsonObj();
            String v2 = v3.optString("source");
            if (v2.equals("headline")) {
                v2 = "click_headline";
            } else if (v2.equals(this.mCategoryName)) {
                v2 = "click_category";
            } else {
                v2 = "click_" + v2;
            }

            try {
                v3.put("group_id", v0);
                v3.put("position", arg8);
                v3.put("share_platform", arg9);
                v3.put("enter_from", v2);
                v3.put("category_name", this.mCategoryName);
                if (this.mArticle != null) {
                    v3.put("user_id", this.mArticle.getUserId());
                }

                if (!AppData.getInstance().getAbSettings().isApplogStaging()) {
                } else {
                    v3.put("_staging_flag", 1);
                }
            } catch (JSONException v0_1) {
            }

            android.support.design.a.onEvent(arg7, v3);
        }
    }

    private void a(Article arg9, long arg10, DisplayMode arg12, boolean arg13) {
        this.a(arg9, arg10, true, arg12, arg13, null);
    }

    public final void a(Article arg13, long arg14, boolean arg16, DisplayMode arg17, boolean arg18, e arg19) {
        boolean v3;
        String v6;
        String v5;
        boolean v11;
        if (arg13 != null && !arg13.delete && this.mActivity != null && (android.support.design.a.isComponentViewValid(this.mActivity))) {
            CallbackCenter.notifyCallback(BaseAppData.callbackTypeShareMiniVideo, new Object[]{Boolean.valueOf(false)});
            this.mArticle = arg13;
            this.c = arg14;
            int v2 = 0;
            this.o = EnumSet.noneOf(CtrlFlag.class);
            String v4 = "";
            this.mDisplayMode = arg17;
            switch (com.ss.android.article.base.feature.e.g.a[arg17.ordinal()]) {
                case 1: {
                    v3 = CommonWXShareHelper.a(this.mActivity, this.mAppData).a();
                    v2 = this.mArticle.articleType == 0 ? 1 : 0;
                    v4 = "";
                    if ((this.C) && this.l != null && this.l.wendaData != null && (this.l.wendaData.canBanComment)) {
                        if (this.l.wendaData.isBanComment) {
                            this.o.add(CtrlFlag.hasAskAllowComment);
                        } else {
                            this.o.add(CtrlFlag.hasAskBanComment);
                        }
                    }

                    if ((this.C) && this.l != null && this.l.wendaData != null && (this.l.wendaData.canDeleteAnswer)) {
                        this.o.add(CtrlFlag.hasAskDeleteAnswer);
                    }

                    if (this.C) {
                        this.o.add(CtrlFlag.disableWeiBo);
                        this.o.add(CtrlFlag.disableTencent);
                        v6 = v4;
                        break;
                    }

                    v6 = v4;
                    break;
                }
                case 2:
                case 3: {
                    v11 = CommonWXShareHelper.a(this.mActivity, this.mAppData).a();
                    v2 = this.mArticle.articleType == 0 ? 1 : 0;
                    if (this.mShareSource == 200) {
                        v4 = "detail";
                    } else if (this.mShareSource == 208) {
                        v4 = "slide_detail";
                    } else {
                        v4 = "list_share";
                    }

                    v5 = arg19 == null ? "share_button" : arg19.a("share_button");
                    MobClickCombiner.onEvent(this.mActivity, v4, v5, this.mArticle.groupId, this.c, this.createExtJsonObj());
                    v6 = v4;
                    v3 = v11;
                    break;
                }
                case 4:
                case 5:
                case 6: {
                    if (this.mArticle.userRepin) {
                        this.o.add(CtrlFlag.hasFavor);
                    }

                    v4 = this.mShareSource == 200 ? "detail" : "list_share";
                    v5 = arg19 == null ? "share_button" : arg19.a("share_button");
                    MobClickCombiner.onEvent(this.mActivity, v4, v5, this.mArticle.groupId, this.c, this.createExtJsonObj());
                    v6 = v4;
                    v3 = false;
                    break;
                }
                case 7: {
                    v11 = CommonWXShareHelper.a(this.mActivity, this.mAppData).a();
                    v2 = this.mArticle.articleType == 0 ? 1 : 0;
                    if ((arg16) && (this.mArticle.userRepin)) {
                        this.o.add(CtrlFlag.hasFavor);
                    }

                    v4 = this.mShareSource == 200 ? "detail" : "list_share";
                    v5 = arg19 == null ? "share_button" : arg19.a("share_button");
                    MobClickCombiner.onEvent(this.mActivity, v4, v5, this.mArticle.groupId, this.c, this.createExtJsonObj());
                    v6 = v4;
                    v3 = v11;
                    break;
                }
                default: {
                    v6 = v4;
                    v3 = false;
                    break;
                }
            }

            label_33:
            if (v3) {
                this.o.add(CtrlFlag.hasWeixin);
            }

            if (v2 != 0 && !this.q) {
                this.o.add(CtrlFlag.hasHtmlShare);
            }

            if (!arg18) {
                this.o.add(CtrlFlag.hasDisplaySetting);
            }

            if (!this.C) {
                this.o.add(CtrlFlag.hasReport);
            } else {
                this.B = "answer_detail";
            }

            DetailActionDialog v2_1 = new DetailActionDialog(this.mActivity, this.D, this.mShareSource, v6, arg17, this.o);
            v2_1.getWindow().setLayout(-2, -2);
            ((BaseActionDialog) v2_1).c = this.c;
            if (this.mDisplayMode == DisplayMode.VIDEO_MORE_WITH_DIGG) {
                if (v2_1.mCancleBtn != null) {
                    v2_1.mCancleBtn.setText(com.ss.android.article.browser.R.string.k4);
                } else {
                    v2_1.a = R.string.k4;
                }
            }

            if (this.l != null && this.l.mMediaInfo != null) {
                MediaInfo mediaInfo = new MediaInfo(this.l.mMediaInfo.id);
                mediaInfo.avatarUrl = this.l.mMediaInfo.avatarUrl;
                v2_1.a(mediaInfo.name, mediaInfo.entryItem.isSubscribed(), mediaInfo.avatarUrl);
            } else if (this.mArticle != null && this.mArticle.mediaInfo != null) {
                v4 = this.mArticle.mediaInfo.name;
                v3 = this.mArticle.mediaInfo != null
                        ? this.mArticle.mediaInfo.entryItem.isSubscribed()
                        : this.mArticle.ah;
                v2_1.a(v4, v3, this.mArticle.mediaInfo.avatarUrl);
            }

            if (this.mArticle != null) {
                v2_1.b = this.mArticle.groupId;
            }

            v2_1.f = this.createExtJsonObj();
            v2_1.setOnDismissListener(new com.ss.android.article.base.feature.e.b(this));
            v2_1.show();
            this.y = true;
        }
    }

    static void a(Object[] arg1) {
        CallbackCenter.notifyCallback(BaseAppData.callbackTypeFeedArticleUmeng, arg1);
    }

    final void a(String arg10) {
        if (!android.support.design.a.isTextEmpty(this.B) && this.mActivity != null) {
            long v4 = 0;
            if (this.mArticle != null) {
                v4 = this.mArticle.groupId;
            }

            String v0 = this.B;
            if (this.mDisplayMode == DisplayMode.DETAIL_MENU) {
                v0 = "detail_more_share";
            }

            String v2 = this.C ? "answer_detail" : v0;
            MobClickCombiner.onEvent(this.mActivity, v2, arg10, v4, this.c, this.createExtJsonObj());
        }
    }

    final void shareToQQ() {
        if (this.mNewArticleDetailTTAndroidObject == null || !this.mNewArticleDetailTTAndroidObject.b("qq")) {
            CommonQQShareHelper commonQQShareHelper = new CommonQQShareHelper(this.mActivity);
            commonQQShareHelper.setAdid(this.c);
            commonQQShareHelper.mActionHelper = this.mActionHelper;
            commonQQShareHelper.mExtJsonObj = this.mExtJsonObj;
            commonQQShareHelper.mShareSource = this.mShareSource;
            commonQQShareHelper.a(this.mArticle);
            this.a("share_qq");
            this.a("rt_share_to_platform", this.position, "qq");
        }
    }

    final void shareToWechat(int arg6) {
        String v0_1;
        if (this.mActivity != null && this.mArticle != null) {
            try {
                if (this.mNewArticleDetailTTAndroidObject != null) {
                    v0_1 = arg6 == 0 ? "weixin" : "weixin_moments";
                    if (this.mNewArticleDetailTTAndroidObject.b(v0_1)) {
                        return;
                    }
                }

                this.a(com.ss.android.article.base.feature.e.m.a(arg6));
                String v1 = "rt_share_to_platform";
                String v2 = this.position;
                v0_1 = arg6 == 0 ? "weixin" : "weixin_moments";
                this.a(v1, v2, v0_1);
                CommonWXShareHelper v0_2 = CommonWXShareHelper.getInstance(this.mActivity, AppData.getInstance(), arg6);
                v0_2.b();
                ((AbsShareHelper) v0_2).mExtJsonObj = this.mExtJsonObj;
                v0_2.mAdid = this.c;
                v0_2.f = this.mActionHelper;
                ((AbsShareHelper) v0_2).mShareSource = this.mShareSource;
                if ((this.C) && this.l != null && this.l.wendaData != null && this.mArticleDetail != null && this.mArticleDetail.spipeUser != null) {
                    v1 = this.mArticleDetail.spipeUser.mScreenName;
                    int v2_1 = this.l.wendaData.diggCount;
                    v0_2.mIsWenda = true;
                    v0_2.g = v1;
                    v0_2.h = v2_1;
                }

                v0_2.a(this.mArticle, new Object[]{Integer.valueOf(arg6)});
            } catch (Exception v0) {
                Logger.d("ArticleShareHelper", "weixin share exception: " + v0.toString());
            }
        }
    }

    public final void a(int arg2, int arg3) {
        if (this.mActivity != null) {
            android.support.design.a.showImageToast(this.mActivity, arg3, arg2);
        }
    }

    public final void a(Article arg9, long arg10) {
        this.a(arg9, arg10, false, DisplayMode.VIDEO_MORE, true, u);
    }

    public final void a(boolean arg6, com.ss.android.article.share.c.a arg7) {
        if (this.l != null && this.l.wendaData != null) {
            com.ss.android.article.common.b.b v1 = com.ss.android.article.common.b.b.a();
            int v0 = arg6 ? 0 : 1;
            v1.a(v0, this.l.wendaData.ansid, this.s, new com.ss.android.article.base.feature.e.d(this, arg6, arg7));
        }
    }

    public final void b(Article arg8, ArticleInfo arg9, long arg10) {
        this.l = arg9;
        this.a(arg8, arg10, DisplayMode.DETAIL_MENU, true);
    }

    private void shareToQZone() {
        if (this.mNewArticleDetailTTAndroidObject == null || !this.mNewArticleDetailTTAndroidObject.b("qzone")) {
            CommonQZoneShareHelper commonQZoneShareHelper = new CommonQZoneShareHelper(this.mActivity);
            commonQZoneShareHelper.setAdid(this.c);
            commonQZoneShareHelper.mActionHelper = this.mActionHelper;
            commonQZoneShareHelper.mExtJsonObj = this.mExtJsonObj;
            commonQZoneShareHelper.mShareSource = this.mShareSource;
            commonQZoneShareHelper.a(this.mArticle);
            this.a("share_qzone");
            this.a("rt_share_to_platform", this.position, "qzone");
        }
    }

    static String b(ArticleShareHelper arg1) {
        return arg1.position;
    }

    public final void b(Article arg9, long arg10) {
        this.a(arg9, arg10, false, DisplayMode.VIDEO_MORE_NO_PGC, true, u);
    }

    public final void c(Article arg8, ArticleInfo arg9, long arg10) {
        this.l = arg9;
        this.a(arg8, arg10, DisplayMode.DETAIL_ALL, true);
    }

    private JSONObject createExtJsonObj() {
        if (this.mExtJsonObj == null) {
            this.mExtJsonObj = new JSONObject();
        }

        try {
            this.mExtJsonObj.put("source", this.detailSource);
            this.mExtJsonObj.put("position", this.position);
            if (this.mArticle != null) {
                this.mExtJsonObj.put("item_id", this.mArticle.itemId);
                this.mExtJsonObj.put("aggr_type", this.mArticle.aggrType);
            }
        } catch (Exception v0) {
            v0.printStackTrace();
        }

        return this.mExtJsonObj;
    }
}

